package www.openteam.com.workorder;


import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.Inputer;
import www.openteam.com.bean.MachineInfo;
import www.openteam.com.bean.PDistrubiton_JijianNumb;
import www.openteam.com.bean.UpdateInfo;
import www.openteam.com.bean.WorkOrder;
import www.openteam.com.mvp.IModel;

/**
 * Created by kylin on 2017/5/3.
 */

public class HZRB_WorkOrderPresenter extends BasePresenter<HZRB_WorkOrderFragment> implements
        HZRB_WorkOrderContract.WorkOrderPresenter {
    @Override
    public void queryUserIsExist(String name) {

        ((HZRB_WorkOrderModel) getiModelMap().get("existName")).queryUserIsExist(name,
                new HZRB_WorkOrderModel.WorkOrderOnListener() {
                    @Override
                    public void successInfo(Inputer inputer) {
                        getIView().queryISuccess(inputer);
                    }

                    @Override
                    public void failInfo(String error) {
                        getIView().queryIFail(error);
                    }
                });

    }

    @Override
    public void queryWO(String barCode, String stype, String morecom,int proCode) {
        ((HZRB_WorkOrderModel) getiModelMap().get("existName")).queryWo(
                barCode, stype, morecom, proCode,new HZRB_WorkOrderModel.WorkOrderWOnListener() {
                    @Override
                    public void suceessWInfo(WorkOrder workOrder) {
                        getIView().queryWSuccess(workOrder
                        );
                    }

                    @Override
                    public void failWInfo(String error) {
                        getIView().queryWFail(error);
                    }
                });
    }

    @Override
    public void findMachine(String code, String inputer, String processid, String rdsno, String stype, String morecom) {
        ((HZRB_WorkOrderModel) getiModelMap().get("existName"))
                .findMachine(code, inputer, processid, rdsno, stype, morecom, new HZRB_WorkOrderModel.WorkOrderMOnListener() {
                    @Override
                    public void suceessMInfo(MachineInfo machineInfo) {
                        getIView().findMSuccess(machineInfo);
                    }

                    @Override
                    public void failMInfo(String error) {
                        getIView().findMFail(error);
                    }
                });
    }

    @Override
    public void updateTimeStatus(String zbid, String procno, String id, String e_Time, String stype, String morecom) {
        ((HZRB_WorkOrderModel) getiModelMap().get("existName")).updateTimeStatus(zbid, procno, id, e_Time, stype, morecom,
                new HZRB_WorkOrderModel.WorkOrderUOnListener() {
                    @Override
                    public void suceessUInfo(UpdateInfo updateInfo) {
                        getIView().updateTSSuccess(updateInfo);
                    }

                    @Override
                    public void failUInfo(String error) {
                        getIView().updateTSFail(error);
                    }
                });
    }

    @Override
    public void findWorkPrice(String machinecode, String banzu, String peopleGroup, String stype, String morecom) {
        ((HZRB_WorkOrderModel) getiModelMap().get("existName")).findWorkPrice(machinecode,
                banzu, peopleGroup, stype, morecom, new HZRB_WorkOrderModel.WorkOrderDisdOnListener() {
                    @Override
                    public void suceessDisdInfo(PDistrubiton_JijianNumb pDistrubition) {
                        getIView().findWPSuccess(pDistrubition);
                    }

                    @Override
                    public void failDisdInfo(String error) {
                        getIView().findMFail(error);
                    }
                });
    }



    @Override
    public void insertSProductionInfo(long InputDate, String zbid, String rdsno,
                                      String orderno, String custid, long StartTime, String PartID,
                                      String PrdID, double TolNumb, String code, String Inputer,
                                      String UserID, String MachinID, String BuilderName,
                                      String InputerName, String procno, String stype, String morecom

    ) {

        ((HZRB_WorkOrderModel) getiModelMap().get("existName")).insertSProductionInfo(
                InputDate, zbid, rdsno, orderno, custid, StartTime, PartID, PrdID,
                TolNumb, code, Inputer, UserID, MachinID, BuilderName, InputerName, procno, stype, morecom, new HZRB_WorkOrderModel.WorkOrderSPOnListener() {
                    @Override
                    public void suceessSPInfo(UpdateInfo updateInfo) {

                        getIView().insertSPSuccess(updateInfo);
                    }

                    @Override
                    public void failSPInfo(String error) {
                        getIView().insertSPFail(error);
                    }
                });
    }

    @Override
    public void insertEProductionInfo(String groupA,
                                      boolean isFinish,
                                      String rdsno,
                                      String GroupCount,
                                      String zbid,
                                      long OverDate,
                                      long EndTime,
                                      String PrdID,
                                      double Numb1,
                                      String MachinID,
                                      String code,
                                      String Inputer,
                                      String procno,
                                      String custid,
                                      String orderno,
                                      double TolNumb,
                                      String PartID,
                                      String BuilderName,
                                      String InputerName,
                                      int userid,
                                      int id,
                                      String banzu, String stype, String morecom,
                                      String prtType, String prtPoNe, String prtColor, String prtCode, String prtPrctType,
                                      String draftflowD, String halfStorage, int changeTime, int waitTime,int delayTime
                                      ,String remark
                                      ) {
        ((HZRB_WorkOrderModel) getiModelMap().get("existName"))
                .insertEProductionInfo(groupA, isFinish, rdsno, GroupCount, zbid, OverDate, EndTime,
                        PrdID, Numb1, MachinID, code, Inputer
                        , procno, custid, orderno, TolNumb, PartID, BuilderName, InputerName, userid, id, banzu,
                        stype, morecom,
                        prtType, prtPoNe, prtColor, prtCode, prtPrctType, draftflowD, halfStorage, changeTime, waitTime,delayTime,remark,
                        new HZRB_WorkOrderModel.WorkOrderEPOnListener() {
                            @Override
                            public void suceessEPInfo(UpdateInfo updateInfo) {
                                getIView().insertEPSuccess(updateInfo);
                            }

                            @Override
                            public void failEPInfo(String error) {
                                getIView().insertEPFail(error);
                            }
                        });
    }


    @Override
    public HashMap<String, IModel> getiModelMap() {

        return loadModelMap(new HZRB_WorkOrderModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("existName", models[0]);
        return hashMap;
    }
}
